| @@ -2,6 +2,7 @@ require 'sinatra' | ||
| 2 | 2 | require 'whois' | 
| 3 | 3 | require 'haml' | 
| 4 | 4 | require 'json' | 
| 5 | +require 'ostruct' | |
| 5 | 6 |  | 
| 6 | 7 | helpers do | 
| 7 | 8 |  | 
| @@ -22,30 +23,41 @@ get '/ip.json' do | ||
| 22 | 23 | end | 
| 23 | 24 |  | 
| 24 | 25 | get '/lookup' do | 
| 25 | - @lookup_info = Whois.query(params[:url]) | |
| 26 | -	@formatted_response = { | |
| 27 | - "domain" => @lookup_info.domain, | |
| 28 | - "created_on" => @lookup_info.created_on, | |
| 29 | - "expires_on" => @lookup_info.expires_on, | |
| 30 | - "whois_server" => @lookup_info.referral_whois, | |
| 31 | - "nameservers" => @lookup_info.nameservers, | |
| 32 | - "admin_contacts" => @lookup_info.admin_contacts[0], | |
| 33 | - "techical_contacts" => @lookup_info.technical_contacts, | |
| 34 | - "detailed" => @lookup_info.to_s.gsub(/\n/, '<br>') | |
| 35 | - } | |
| 36 | - haml :lookup | |
| 26 | + begin | |
| 27 | + @lookup_info = Whois.query(params[:url]) | |
| 28 | + admin_contacts = Hash[@lookup_info.admin_contacts[0].each_pair.to_a] | |
| 29 | + technical_contacts = Hash[@lookup_info.technical_contacts[0].each_pair.to_a] | |
| 30 | + | |
| 31 | +		@formatted_response = { | |
| 32 | + "domain" => @lookup_info.domain, | |
| 33 | + "created_on" => @lookup_info.created_on, | |
| 34 | + "expires_on" => @lookup_info.expires_on, | |
| 35 | + "whois_server" => @lookup_info.referral_whois, | |
| 36 | + "nameservers" => @lookup_info.nameservers, | |
| 37 | + "admin_contacts" => admin_contacts, | |
| 38 | + "techical_contacts" => technical_contacts | |
| 39 | + } | |
| 40 | + haml :lookup | |
| 41 | + rescue | |
| 42 | + haml :error | |
| 43 | + end | |
| 37 | 44 | end | 
| 38 | 45 |  | 
| 39 | 46 | get '/lookup.json' do | 
| 40 | - @lookup_info = Whois.query(params[:url]) | |
| 41 | - content_type :json | |
| 42 | -	{ :domain => @lookup_info.domain, | |
| 43 | - :created_on => @lookup_info.created_on, | |
| 44 | - :expires_on => @lookup_info.expires_on, | |
| 45 | - :whois_server => @lookup_info.referral_whois, | |
| 46 | - :nameservers => @lookup_info.nameservers, | |
| 47 | - :admin_contacts => @lookup_info.admin_contacts[0], | |
| 48 | - :techical_contacts => @lookup_info.technical_contacts[0], | |
| 49 | - :detailed => @lookup_info | |
| 50 | - }.to_json | |
| 47 | + begin | |
| 48 | + @lookup_info = Whois.query(params[:url]) | |
| 49 | + admin_contacts = Hash[@lookup_info.admin_contacts[0].each_pair.to_a] | |
| 50 | + technical_contacts = Hash[@lookup_info.technical_contacts[0].each_pair.to_a] | |
| 51 | + content_type :json | |
| 52 | +		{ :domain => @lookup_info.domain, | |
| 53 | + :created_on => @lookup_info.created_on, | |
| 54 | + :expires_on => @lookup_info.expires_on, | |
| 55 | + :whois_server => @lookup_info.referral_whois, | |
| 56 | + :nameservers => @lookup_info.nameservers, | |
| 57 | + :admin_contacts => admin_contacts, | |
| 58 | + :techical_contacts => technical_contacts | |
| 59 | + }.to_json | |
| 60 | + rescue | |
| 61 | +		{"Error" => "Bad Request"}.to_json | |
| 62 | + end | |
| 51 | 63 | end | 
| @@ -0,0 +1,36 @@ | ||
| 1 | +@font-face { | |
| 2 | + font-family: 'Orbitron'; | |
| 3 | + font-style: normal; | |
| 4 | + font-weight: 400; | |
| 5 | +  src: local('Orbitron'), url('/fonts/orbitron_medium') format('opentype'); | |
| 6 | +} | |
| 7 | + | |
| 8 | + | |
| 9 | +body { | |
| 10 | + font-family: 'Orbitron', sans-serif; | |
| 11 | + font-size: 14px; | |
| 12 | + background: #dedede; | |
| 13 | +} | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | +p { | |
| 18 | + margin: 0; | |
| 19 | +} | |
| 20 | + | |
| 21 | +.info { | |
| 22 | + width: 500px; | |
| 23 | + margin: 0 auto 15px auto; | |
| 24 | + padding: 15px; | |
| 25 | + border: solid 1px #ccc; | |
| 26 | + background-color: white; | |
| 27 | + box-shadow: 0 0 5px rgba(0,0,0,0.2); | |
| 28 | +} | |
| 29 | + | |
| 30 | +p.title { | |
| 31 | + font-weight: bold; | |
| 32 | + font-size: 1.1em; | |
| 33 | + margin: 0 0 10px 0; | |
| 34 | + padding-bottom: 3px; | |
| 35 | + border-bottom: solid 1px #ccc; | |
| 36 | +} | 
| @@ -0,0 +1,8 @@ | ||
| 1 | +!!! | |
| 2 | +%html | |
| 3 | + %head | |
| 4 | + %title A free whois API service | |
| 5 | +    %link{:rel => "stylesheet", :type => "text/css", :href => "/css/styles.css"} | |
| 6 | + %body | |
| 7 | + .info | |
| 8 | + %h1 Error: invalid request | 
| @@ -1,10 +1,12 @@ | ||
| 1 | 1 | !!! | 
| 2 | 2 | %html | 
| 3 | - %head | |
| 4 | - %title A free whois API service | |
| 5 | - %body | |
| 6 | - %p Just enter a URL, to do a WHOIS lookup. | |
| 3 | + %head | |
| 4 | + %title A free whois API service | |
| 5 | +    %link{:rel => "stylesheet", :type => "text/css", :href => "/css/styles.css"} | |
| 6 | + %body | |
| 7 | + .info | |
| 8 | + %p.title Just enter a URL, to do a WHOIS lookup. | |
| 7 | 9 |  | 
| 8 | -		%form{ :action => "/lookup", :method => "get"} | |
| 9 | -			%input{ :type => "text", :name => "url"} | |
| 10 | -			%input{ :type => "submit", :value => "Lookup Whois"} | |
| 10 | +      %form{ :action => "/lookup", :method => "get"} | |
| 11 | +        %input{ :type => "text", :name => "url"} | |
| 12 | +        %input.submit{ :type => "submit", :value => "Lookup Whois"} | 
| @@ -2,46 +2,48 @@ | ||
| 2 | 2 | %html | 
| 3 | 3 | %head | 
| 4 | 4 | %title A free whois API service | 
| 5 | +		%link{:rel => "stylesheet", :type => "text/css", :href => "/css/styles.css"} | |
| 5 | 6 | %body | 
| 6 | - | |
| 7 | - %h3 URL | |
| 8 | -		%div{:style => "border: solid 1px black; padding: 10px; border-radius: 15px"} | |
| 9 | - = @formatted_response["domain"] | |
| 10 | - | |
| 11 | - %h3 Admin Contact | |
| 12 | -		%div{:style => "border: solid 1px black; padding: 10px; border-radius: 15px"} | |
| 13 | - - if @formatted_response["admin_contacts"] | |
| 14 | - - @formatted_response["admin_contacts"].each do |contact| | |
| 15 | - = contact.to_s + " <br />" | |
| 16 | - - else | |
| 17 | - = "none" | |
| 18 | - | |
| 19 | - %h3 Technical Contact | |
| 20 | -		%div{:style => "border: solid 1px black; padding: 10px; border-radius: 15px"} | |
| 21 | - - if @formatted_response["technical_contacts"] | |
| 22 | - - @formatted_response["technical_contacts"].each do |contact| | |
| 23 | - = contact.to_s + " <br />" | |
| 24 | - - else | |
| 25 | - = "none" | |
| 26 | - | |
| 27 | - %h3 Create Date | |
| 28 | -		%div{:style => "border: solid 1px black; padding: 10px; border-radius: 15px"} | |
| 29 | - = @formatted_response["created_on"] | |
| 30 | - | |
| 31 | - %h3 Expire Date | |
| 32 | -		%div{:style => "border: solid 1px black; padding: 10px; border-radius: 15px"} | |
| 33 | - = @formatted_response["expires_on"] | |
| 34 | - | |
| 35 | - %h3 WHOIS Server | |
| 36 | -		%div{:style => "border: solid 1px black; padding: 10px; border-radius: 15px"} | |
| 37 | - = @formatted_response["whois_server"] | |
| 38 | - | |
| 39 | - %h3 Nameservers | |
| 40 | -		%div{:style => "border: solid 1px black; padding: 10px; border-radius: 15px"} | |
| 41 | - - @formatted_response["nameservers"].each do |name| | |
| 42 | - = name.to_s + " <br />" | |
| 43 | - | |
| 44 | - %h3 Detailed Response | |
| 45 | -		%div{:style => "border: solid 1px black; padding: 10px; border-radius: 15px"} | |
| 46 | - = @formatted_response["detailed"] | |
| 47 | - | |
| 7 | + .info | |
| 8 | + %p.title URL | |
| 9 | + %p.content | |
| 10 | + = @formatted_response["domain"] | |
| 11 | + | |
| 12 | + .info | |
| 13 | + %p.title Admin Contact | |
| 14 | + %p.content | |
| 15 | + - if @formatted_response["admin_contacts"] | |
| 16 | + - @formatted_response["admin_contacts"].each do |contact| | |
| 17 | + = "<strong>" + contact[0].to_s + "</strong>: " + contact[1].to_s + "<br />" | |
| 18 | + - else | |
| 19 | + = "none" | |
| 20 | + | |
| 21 | + .info | |
| 22 | + %p.title Technical Contact | |
| 23 | + %p.content | |
| 24 | + - if @formatted_response["technical_contacts"] | |
| 25 | + - @formatted_response["technical_contacts"].each do |contact| | |
| 26 | + = contact.to_s + " <br />" | |
| 27 | + - else | |
| 28 | + = "none" | |
| 29 | + | |
| 30 | + .info | |
| 31 | + %p.title Create Date | |
| 32 | + %p.content | |
| 33 | + = @formatted_response["created_on"] | |
| 34 | + | |
| 35 | + .info | |
| 36 | + %p.title Expire Date | |
| 37 | + %p.content | |
| 38 | + = @formatted_response["expires_on"] | |
| 39 | + | |
| 40 | + .info | |
| 41 | + %p.title WHOIS Server | |
| 42 | + %p.content | |
| 43 | + = @formatted_response["whois_server"] | |
| 44 | + | |
| 45 | + .info | |
| 46 | + %p.title Nameservers | |
| 47 | + %p.content | |
| 48 | + - @formatted_response["nameservers"].each do |name| | |
| 49 | + = name.to_s + " <br />" |